package com.ruoyi.chiwen.api;

import com.ruoyi.chiwen.domain.TbIdCard;
import com.ruoyi.chiwen.service.ApiCommonService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.UserTokenService;
import com.ruoyi.framework.web.service.WxLoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: ruoyi
 * @description:
 * @author: 佐佐木
 * @create: 2021-06-15 22:50
 **/
@RestController
@RequestMapping(value = "/chiwen/api/common")
public class ApiCommonController {

    @Autowired
    private ApiCommonService apiCommonService;

    @Autowired
    private UserTokenService userTokenService;


    /**
     * @Description: 身份证识别接口
     * @Param: [userId,imgUrl]
     */
    @GetMapping(value = "/getIdCard")
    public AjaxResult getIdCard( String imgUrl ){
        System.out.println(imgUrl);
        return   apiCommonService.getIdCode(imgUrl);
    }

    @GetMapping(value = "/getIdCard2")
    public AjaxResult getIdCard2( String imgUrl ){
        System.out.println(imgUrl);
        return   apiCommonService.getIdCard2(imgUrl);
    }


    /**
     * @Description: 身份证识别接口
     * @Param: [userId,imgUrl]
     */
    @PostMapping(value = "/saveIdCard")
    public AjaxResult saveIdCard(@RequestBody TbIdCard imgUrl, HttpServletRequest request){
        String token = userTokenService.getToken(request);
        WxLoginUser wxLoginUser = userTokenService.getWxLoginUser(token);
        Long userId= wxLoginUser.getUserId();
        return   apiCommonService.saveIdCard(userId,imgUrl);
    }

    /**
     * @Description: 身份证识别接口
     * @Param: [userId,imgUrl]
     */
    @GetMapping(value = "/changeStage")
    public AjaxResult changeStage(String num, HttpServletRequest request){
        String token = userTokenService.getToken(request);
        WxLoginUser wxLoginUser = userTokenService.getWxLoginUser(token);
        Long userId= wxLoginUser.getUserId();
        return   apiCommonService.changeStage(userId,num);
    }

    /**
     * @Description: 银行卡识别接口
     * @Param: [userId,imgUrl]
     */
    @GetMapping(value = "/getBankCard")
    public AjaxResult getBankCard(HttpServletRequest request,String imgUrl ){
        String token = userTokenService.getToken(request);
        WxLoginUser wxLoginUser = userTokenService.getWxLoginUser(token);
        Long userId= wxLoginUser.getUserId();
        return   apiCommonService.getBankCard(userId,imgUrl);
    }



}
